package com.example.community.list;

import com.example.community.dao.ParkingDao;
import com.example.community.model.Parking;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/fpcw")
public class FpcwServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String usNo = req.getParameter("usNo");
        req.setAttribute("usNo",usNo);
        ParkingDao parkingDao = new ParkingDao();
        List<Parking> parkings = parkingDao.selectNull();
        req.setAttribute("parkings",parkings);
        req.getRequestDispatcher("/WEB-INF/userManager/fpcw.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String fpcw = req.getParameter("fpcw");
        String usNo = req.getParameter("usNo");
        ParkingDao parkingDao = new ParkingDao();
        Parking parking = new Parking();
        parking.setpNo(Integer.parseInt(fpcw));
        parking.setUsNo(Integer.parseInt(usNo));
        Integer update = parkingDao.update(parking);
        if (update == 1){
            resp.getWriter().write("true");
        }else {
            resp.getWriter().write("false");
        }

    }
}
